package com.example.x6.configurationmaintenance.Notification;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
import com.example.x6.configurationmaintenance.Activity.UpdateActivity;
import com.example.x6.configurationmaintenance.R;
import java.util.HashMap;
import java.util.Map;

public class NotificationUtil {
    private Context context;
    private NotificationManager manager;
    private Map<Integer, Notification> map = null;

    public NotificationUtil(Context context2) {
        this.context = context2;
        this.manager = (NotificationManager) this.context.getSystemService("notification");
        this.map = new HashMap();
    }

    public void showNotification(int notificationId, String tickerText) {
        if (!this.map.containsKey(Integer.valueOf(notificationId))) {
            Notification notification = new Notification();
            if (tickerText == null || tickerText.isEmpty()) {
                notification.tickerText = String.format(this.context.getResources().getString(R.string.app_update), this.context.getResources().getString(R.string.app_name));
            } else {
                notification.tickerText = tickerText;
            }
            notification.when = System.currentTimeMillis();
            notification.icon = R.drawable.ic_tab_selected_download;
            notification.flags = 32;
            notification.contentIntent = PendingIntent.getActivity(this.context, 0, new Intent(this.context, UpdateActivity.class), 0);
            notification.contentView = new RemoteViews(this.context.getPackageName(), (int) R.layout.notification_contentview);
            this.manager.notify(notificationId, notification);
            this.map.put(Integer.valueOf(notificationId), notification);
        }
    }

    public void cancel(int notificationId) {
        this.manager.cancel(notificationId);
        this.map.remove(Integer.valueOf(notificationId));
    }

    public void updateProgress(int notificationId, int progress) {
        Notification notification = this.map.get(Integer.valueOf(notificationId));
        if (notification != null) {
            notification.contentView.setProgressBar(R.id.pBar, 100, progress, false);
            this.manager.notify(notificationId, notification);
        }
    }
}
